package com.beauty.product.repository.es;

import com.beauty.product.document.ProductDocument;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ProductDocumentRepository extends ElasticsearchRepository<ProductDocument, String> {
    
    Optional<ProductDocument> findBySku(String sku);
    
    Page<ProductDocument> findByCategoryId(Long categoryId, Pageable pageable);
    
    Page<ProductDocument> findByIsPublished(Boolean isPublished, Pageable pageable);
    
    Page<ProductDocument> findByIsRecommended(Boolean isRecommended, Pageable pageable);
    
    Page<ProductDocument> findByIsNew(Boolean isNew, Pageable pageable);
    
    Page<ProductDocument> findByIsHot(Boolean isHot, Pageable pageable);
    
    @Query("{\"bool\": {\"should\": [{\"match\": {\"name\": \"?0\"}}, {\"match\": {\"brand\": \"?0\"}}, {\"match\": {\"description\": \"?0\"}}, {\"match\": {\"attributes.value\": \"?0\"}}]}}")
    Page<ProductDocument> searchByKeyword(String keyword, Pageable pageable);
    
    List<ProductDocument> findTop10ByOrderBySalesDesc();
} 